#ifndef SNAKE_H
#define SNAKE_H

#include <QGraphicsItem>
#include <QObject>
#include <QStack>
#include <QQueue>

class GameController;

class Snake : public QGraphicsItem
{
public:
    Snake(GameController &m_controller);

    enum Direction {
        NoMove,
        MoveLeft,
        MoveRight,
        MoveUp,
        MoveDown
    };

    ~Snake();

    void setMoveDirection(Direction type);
    QRectF boundingRect() const Q_DECL_OVERRIDE;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem* ,QWidget *)Q_DECL_OVERRIDE;
    QPainterPath shape() const Q_DECL_OVERRIDE;
protected:
    void advance(int step) Q_DECL_OVERRIDE;

private:
    void moveLeft();
    void moveRight();
    void moveUp();
    void moveDown();

    void handleCollisions();

    QPointF m_head;
    int m_growing;
    int m_speed;
    QList<QPointF> m_tail;
    int m_tickCounter;
    Direction m_moveDirection;

    QQueue<Direction> m_queue;

    GameController &m_controller;
};

#endif // SNAKE_H
